import { AppInfo, AppVersionData, DeviceInfo } from "@/api/entity/basic";

//是否Android设备
const isAndroid = (platform : string) : boolean => {
	return platform == 'android'
}

//是否iOS设备
const isIOS = (platform : string) : boolean => {
	return platform == 'ios'
}

//是否鸿蒙设备
const isHarmony = (platform : string) : boolean => {
	return platform == 'harmony'
}

//返回APP包名
const _getAppPackageName = (platform : string) : string => {
	if (isAndroid(platform)) {
		return 'com.kn.doctorapp'
	}
	if (isIOS(platform)) {
		return 'com.kn.doctorapp2'
	}
	if (isHarmony(platform)) {
		return 'com.kn.ynjkdoctorapp'
	}
	return ''
}

//返回设备类型标记 1-iOS 2-Android 3-Harmony
const _getDeviceType = (platform : string) : number => {
	if(isAndroid(platform)) {
		return 2
	}
	if (isIOS(platform)) {
		return 1
	}
	if(isHarmony(platform)) {
		return 3
	}
	return 0
}

const getPlatform = () : string => {
	return uni.getSystemInfoSync().platform
}

//获取APP版本信息
const getAppInfo = () : AppInfo => {
	const systemInfo = uni.getSystemInfoSync()
	return {
		versionCode: systemInfo.appVersionCode,
		versionName: systemInfo.appVersion,
		platform: systemInfo.platform,
		packageName: _getAppPackageName(systemInfo.platform),
		deviceType: _getDeviceType(systemInfo.platform),
	}
}

//获取设备信息
const getDeviceInfo = () : DeviceInfo => {
	const systemInfo = uni.getSystemInfoSync()
	return {
		deviceId: systemInfo.deviceId,
		deviceType: _getDeviceType(systemInfo.platform),
		deviceName: systemInfo.deviceModel,
		deviceVersion: systemInfo.appVersion,
		deviceModel : systemInfo.deviceModel,
		deviceManufacturer: systemInfo.deviceBrand,
		systemVersion: systemInfo.osVersion
	}
}

//检查版本更新
const checkAppUpdate = (data: AppVersionData) : void => {
	
}

//导出
export {
	isAndroid,
	isIOS,
	isHarmony,
	getAppInfo,
	getDeviceInfo,
	checkAppUpdate,
	getPlatform,
}